//
//  VC_LoginSMS.m
//  yjw-winner
//
//  Created by 王春辉 on 2018/9/15.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "VC_LoginSMS.h"

@interface VC_LoginSMS ()

@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UITextField *accountTextField;
@property (weak, nonatomic) IBOutlet UITextField *vertifyTextField;
@property (weak, nonatomic) IBOutlet UIButton *smsCodeButton;

@property (weak, nonatomic) IBOutlet UIButton *loginButton;
@property (weak, nonatomic) IBOutlet UIButton *registButton;
@end

@implementation VC_LoginSMS

- (void)viewDidLoad {
    [super viewDidLoad];
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = self.headImageView.mj_w * 0.5;
    
    self.loginButton.layer.masksToBounds = YES;
    self.loginButton.layer.cornerRadius = 4.0f;
    
    self.registButton.layer.masksToBounds = YES;
    self.registButton.layer.cornerRadius = 4.0f;
    self.registButton.layer.borderColor = [UIColor grayColor].CGColor;
    self.registButton.layer.borderWidth = 1.0f;
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSInteger index = [CountDownManager manager].currentCount;
    if (index == 60) {
        [self.smsCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
    }else {
        [self countDown];
    }
}

#pragma mark --mark EVENT

- (IBAction)wechatButtonClick:(UIButton *)sender {
    [MBProgressHUD showSuccess:@"微信登录"];
}
- (IBAction)qqButtonClick:(UIButton *)sender {
    [MBProgressHUD showSuccess:@"qq登录"];
}
- (IBAction)sinaButtonClick:(UIButton *)sender {
    [MBProgressHUD showSuccess:@"新浪微博登录"];
}
- (IBAction)getSMSCodeButtonClick:(UIButton *)sender {
    if ([CountDownManager manager].currentCount == 60) {
        // 获取短信
        // 倒计时
        [self countDown];
    }else {
        
    }
}
- (void)countDown {
    __weak typeof(self) weakself = self;
    [[CountDownManager manager] startWithCountDownManagerBlock:^(NSInteger number) {
        if (number > 0 && number < 60) {
            [weakself.smsCodeButton setTitle:[NSString stringWithFormat:@"%ld", number] forState:UIControlStateNormal];
        }else {
            [weakself.smsCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
        }
    }];
}
- (IBAction)unwindForSegue:(UIStoryboardSegue *)unwindSegue towardsViewController:(UIViewController *)subsequentVC {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
